package cn.ssq.service.impl;

import cn.ssq.dao.BacterialStrainInfoMapper;
import cn.ssq.dao.SampleInfoMapper;
import cn.ssq.service.BacterialStrainfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BacterialStrainfoServiceImpl implements BacterialStrainfoService {
    @Autowired
    private BacterialStrainInfoMapper bacterialStrainInfoMapper;
    @Autowired
    private SampleInfoMapper sampleInfoMapper;
    /**
     * 修改样品毒株信息
     * @param sampleId
     * @return
     */
    @Override
    public int updateBacterialStrainfo(Integer sampleId) {
        int i1 = bacterialStrainInfoMapper.updateByPrimaryKey(sampleId);
        return i1;
    }


    //添加产毒菌株信息
    @Override
    public int addBacterialStrainfo(Integer sid, List<String> originalNum, List<String> wordAddr, List<String> txtAddr, List<String> pictureAddr) {
        String sampleId = sampleInfoMapper.selectIdBySampleId(sid);
        String idesl="0";
        int i1 = Integer.parseInt(idesl);
        Integer insert=0;
        if (originalNum!=null&&originalNum.size()>0&&wordAddr!=null&&wordAddr.size()>0&&txtAddr!=null&&txtAddr.size()>0&&pictureAddr!=null&&pictureAddr.size()>0) {
            for (int i = 0; i < originalNum.size(); i++) {
                insert = bacterialStrainInfoMapper.insert(sid,sampleId , originalNum.get(i),wordAddr.get(i), txtAddr.get(i), pictureAddr.get(i), i1);
            }
        }else {
            bacterialStrainInfoMapper.insert(sid,sampleId,null,null,null,null,i1);
        }
        return insert;
    }

    @Override
    public Integer[] selectSamId(Integer samId) {
        return bacterialStrainInfoMapper.selectSamId(samId);
    }

    @Override
    public int insertByIdb(String sampleId,String originalNum) {
        return bacterialStrainInfoMapper.insertIntoById(sampleId,originalNum);
    }
}
